package obecto.component.textField
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.TextEvent;
	import flash.text.StyleSheet;
	import flash.text.TextField;
	import flash.text.TextFormat;
	
	import obecto.core.FLUIComponent;
	import obecto.utility.ObjectPropertiesProxy;
	
	[Event(name="change", type="flash.events.Event")]
	[Event(name="textInput", type="flash.events.TextEvent")]
	
	public class FLTextField extends FLUIComponent
	{
		[Bindable]
		public var textField : TextField;
		
		private var textFieldPropertiesProxy : ObjectPropertiesProxy;
		
		[Bindable("textChanged")]
		public function get text() : String
		{
			return textFieldPropertiesProxy.getProperty("text");
		}
		public function set text(value : String) : void
		{
			textFieldPropertiesProxy.setProperty("text", value);
			dispatchEvent(new Event("textChanged"));	
		}
		
		[Bindable("textChanged")]
		public function get htmlText() : String
		{
			return textFieldPropertiesProxy.getProperty("htmlText");
		}
		public function set htmlText(value : String) : void
		{
			textFieldPropertiesProxy.setProperty("htmlText", value);
			dispatchEvent(new Event("textChanged"));	
		}
		
		override public function set width(value:Number) : void
		{
			super.width = value;
			textFieldPropertiesProxy.setProperty("width", value);
		}
		
		override public function set height(value:Number) : void
		{
			super.height = value;
			textFieldPropertiesProxy.setProperty("height", value);
		}
		
		[Bindable]
		public function get useRichTextClipboard() : Boolean
		{
			return textFieldPropertiesProxy.getProperty("useRichTextClipboard");
		}
		public function set useRichTextClipboard(value : Boolean) : void
		{
			textFieldPropertiesProxy.setProperty("useRichTextClipboard", value);
		}

		[Bindable]
		public function get type() : String
		{
			return textFieldPropertiesProxy.getProperty("type");
		}
		public function set type(value : String) : void
		{
			textFieldPropertiesProxy.setProperty("type", value);
		}

		[Bindable]
		public function get scrollH() : int
		{
			return textFieldPropertiesProxy.getProperty("scrollH");
		}
		public function set scrollH(value : int) : void
		{
			textFieldPropertiesProxy.setProperty("scrollH", value);
		}
		
		[Bindable]
		public function get textColor() : uint
		{
			return textFieldPropertiesProxy.getProperty("textColor");
		}
		public function set textColor(value : uint) : void
		{
			textFieldPropertiesProxy.setProperty("textColor", value);
		}

		[Bindable]
		public function get autoSize() : String
		{
			return textFieldPropertiesProxy.getProperty("autoSize");
		}
		public function set autoSize(value : String) : void
		{
			textFieldPropertiesProxy.setProperty("autoSize", value);
		}

		[Bindable]
		public function get defaultTextFormat() : TextFormat
		{
			return textFieldPropertiesProxy.getProperty("defaultTextFormat");
		}
		public function set defaultTextFormat(value : TextFormat) : void
		{
			textFieldPropertiesProxy.setProperty("defaultTextFormat", value);
		}

		[Bindable]
		public function get scrollV() : int
		{
			return textFieldPropertiesProxy.getProperty("scrollV");
		}
		public function set scrollV(value : int) : void
		{
			textFieldPropertiesProxy.setProperty("scrollV", value);
		}

		[Bindable]
		public function get backgroundColor() : uint
		{
			return textFieldPropertiesProxy.getProperty("backgroundColor");
		}
		public function set backgroundColor(value : uint) : void
		{
			textFieldPropertiesProxy.setProperty("backgroundColor", value);
		}

		[Bindable]
		public function get embedFonts() : Boolean
		{
			return textFieldPropertiesProxy.getProperty("embedFonts");
		}
		public function set embedFonts(value : Boolean) : void
		{
			textFieldPropertiesProxy.setProperty("embedFonts", value);
		}

		[Bindable]
		public function get maxChars() : int
		{
			return textFieldPropertiesProxy.getProperty("maxChars");
		}
		public function set maxChars(value : int) : void
		{
			textFieldPropertiesProxy.setProperty("maxChars", value);
		}

		[Bindable]
		public function get border() : Boolean
		{
			return textFieldPropertiesProxy.getProperty("border");
		}
		public function set border(value : Boolean) : void
		{
			textFieldPropertiesProxy.setProperty("border", value);
		}

		[Bindable]
		public function get background() : Boolean
		{
			return textFieldPropertiesProxy.getProperty("background");
		}
		public function set background(value : Boolean) : void
		{
			textFieldPropertiesProxy.setProperty("background", value);
		}

		[Bindable]
		public function get antiAliasType() : String
		{
			return textFieldPropertiesProxy.getProperty("antiAliasType");
		}
		public function set antiAliasType(value : String) : void
		{
			textFieldPropertiesProxy.setProperty("antiAliasType", value);
		}

		[Bindable]
		public function get selectable() : Boolean
		{
			return textFieldPropertiesProxy.getProperty("selectable");
		}
		public function set selectable(value : Boolean) : void
		{
			textFieldPropertiesProxy.setProperty("selectable", value);
		}

		[Bindable]
		public function get multiline() : Boolean
		{
			return textFieldPropertiesProxy.getProperty("multiline");
		}
		public function set multiline(value : Boolean) : void
		{
			textFieldPropertiesProxy.setProperty("multiline", value);
		}

		[Bindable]
		public function get alwaysShowSelection() : Boolean
		{
			return textFieldPropertiesProxy.getProperty("alwaysShowSelection");
		}
		public function set alwaysShowSelection(value : Boolean) : void
		{
			textFieldPropertiesProxy.setProperty("alwaysShowSelection", value);
		}

		[Bindable]
		public function get sharpness() : Number
		{
			return textFieldPropertiesProxy.getProperty("sharpness");
		}
		public function set sharpness(value : Number) : void
		{
			textFieldPropertiesProxy.setProperty("sharpness", value);
		}

		[Bindable]
		public function get wordWrap() : Boolean
		{
			return textFieldPropertiesProxy.getProperty("wordWrap");
		}
		public function set wordWrap(value : Boolean) : void
		{
			textFieldPropertiesProxy.setProperty("wordWrap", value);
		}

		[Bindable]
		public function get displayAsPassword() : Boolean
		{
			return textFieldPropertiesProxy.getProperty("displayAsPassword");
		}
		public function set displayAsPassword(value : Boolean) : void
		{
			textFieldPropertiesProxy.setProperty("displayAsPassword", value);
		}

		[Bindable]
		public function get mouseWheelEnabled() : Boolean
		{
			return textFieldPropertiesProxy.getProperty("mouseWheelEnabled");
		}
		public function set mouseWheelEnabled(value : Boolean) : void
		{
			textFieldPropertiesProxy.setProperty("mouseWheelEnabled", value);
		}

		[Bindable]
		public function get thickness() : Number
		{
			return textFieldPropertiesProxy.getProperty("thickness");
		}
		public function set thickness(value : Number) : void
		{
			textFieldPropertiesProxy.setProperty("thickness", value);
		}

		[Bindable]
		public function get restrict() : String
		{
			return textFieldPropertiesProxy.getProperty("restrict");
		}
		public function set restrict(value : String) : void
		{
			textFieldPropertiesProxy.setProperty("restrict", value);
		}

		[Bindable]
		public function get gridFitType() : String
		{
			return textFieldPropertiesProxy.getProperty("gridFitType");
		}
		public function set gridFitType(value : String) : void
		{
			textFieldPropertiesProxy.setProperty("gridFitType", value);
		}

		[Bindable]
		public function get borderColor() : uint
		{
			return textFieldPropertiesProxy.getProperty("borderColor");
		}
		public function set borderColor(value : uint) : void
		{
			textFieldPropertiesProxy.setProperty("borderColor", value);
		}

		[Bindable]
		public function get condenseWhite() : Boolean
		{
			return textFieldPropertiesProxy.getProperty("condenseWhite");
		}
		public function set condenseWhite(value : Boolean) : void
		{
			textFieldPropertiesProxy.setProperty("condenseWhite", value);
		}

		[Bindable]
		public function get styleSheet() : StyleSheet
		{
			return textFieldPropertiesProxy.getProperty("styleSheet");
		}
		public function set styleSheet(value : StyleSheet) : void
		{
			textFieldPropertiesProxy.setProperty("styleSheet", value);
		}
			
		public function FLTextField()
		{
			super();
			
			_view = new Sprite();
			
			textFieldPropertiesProxy = new ObjectPropertiesProxy();
		}
		
		override protected function initialize() : void
		{
			if (!textField)
			{
				textField = createTextField();
				addChild(textField);
			}
			
			textFieldPropertiesProxy.target = textField;
			
			super.width = textFieldPropertiesProxy.getProperty("width");
			super.height = textFieldPropertiesProxy.getProperty("height");
			
			textField.addEventListener(TextEvent.TEXT_INPUT, handleTextInput);
			textField.addEventListener(Event.CHANGE, handleTextFieldChange);
		}
		
		protected function createTextField() : TextField
		{
			var result : TextField = new TextField();
			return result;
		}
		
		private function handleTextInput(event : TextEvent) : void
		{
			dispatchEvent(new Event("textChanged"));
		}
		
		private function handleTextFieldChange(event : Event) : void
		{
			dispatchEvent(new Event("textChanged"));
		}
	}
}